Types of Subroutines
There are two types of subroutines: those with labeled parameters and those with positional parameters.
For example, the following statement calls a subroutine with positional parameters.
- Labeled parameters are identified by their labels and can be listed in any order. Subroutines with labeled parameters can also have a direct parameter. The direct parameter, if present, must be listed first.
- Positional parameters must be listed in a specific order, which is defined in the subroutine definition.
minimumValue(150, 4000)The following statement calls a subroutine with labeled parameters. The direct parameter is the list of filenames. The labeled parameters are identified by the labelsstringToFind
andcheckCase
.
findFiles of {"March Expenses", "April Expenses", ÿ "May Expenses", "June Expenses"} given ÿ stringToFind:"LeChateau", checkCase:falseThe definition for a subroutine determines what kind of parameters the subroutine requires. When you call a subroutine, you must list its parameters in the same way they are specified in the subroutine definition.You can also have subroutines with no parameters. To indicate that a subroutine has no parameters, you must include a pair of empty parentheses after the subroutine name in both the subroutine definition and the subroutine call. For example, the following script shows the definition and subroutine call for a subroutine called
helloWorld
that has no parameters.
on helloWorld() display dialog "Hello World"end helloWorld()